@import "../../include/vars";

:root {
    --switch-background: #e9e9e9;
    --switch-background-checked: #191919;    
    --switch-background-disabled: #e8e8e8;    
    --switch-toggle-color: #fff;    
    --switch-toggle-disabled: #ccc;
    --switch-text-color: #000;
    --switch-text-color-checked: #fff;
    --switch-focus-color: #e8e8e8;
}

.dark-side {
    --switch-background: #232527;
    --switch-background-checked: #474748;
    --switch-toggle-color: #fff;
    --switch-toggle-disabled: #3e4145;
    --switch-text-color: #efefef;
    --switch-text-color-checked: #fff;
    --switch-focus-color: #191919;
}

.switch {
    height: 36px;
    padding: 8px 0;
    margin: 0 .25rem;
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    cursor: pointer;
    width: auto;
    flex-wrap: nowrap;
    
    & > input {
        appearance: none;
        position: relative;
        width: 48px;
        height: 20px;
        order: 2;
        background: var(--switch-background);
        border-radius: 10px;
        cursor: pointer;
        transition: 0.3s background-color;
        margin: 0;
        padding: 0;
        border-color: transparent!important;
        
        &::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 16px;
            height: 16px;
            background: var(--switch-toggle-color);
            border-radius: 50%;
            transition: 0.3s;
            opacity: 1;
            border: 1px solid transparent;
            transform: none;
        }
        
        &::after {
            position: absolute;
            content: attr(data-off);
            top: 5px;
            left: 2px;
            transform: translate(20px, 0);
            color: var(--switch-text-color);
            text-transform: uppercase;
            font-size: 8px;
            font-weight: 400;
            transition: 0.3s transform;
            line-height: 1;
        }
        
        &:checked {
            background: var(--switch-background-checked);
            
            &::before {
                transform: translateX(28px);
            }
            
            &::after {
                content: attr(data-on);
                transform: translateX(6px);
                color: var(--switch-text-color-checked);
            }
        }
        
        &:disabled {
            background: var(--switch-background-disabled);
            
            &::before {
                background: var(--switch-toggle-disabled);
            }
        }
    }
    
    .caption-prepend, .caption-append {
        font-size: 12px;
        margin: 0 6px;
        position: relative;
        white-space: nowrap;
    }
    
    .caption-prepend {
        order: 1;
    }
    
    .caption-append {
        order: 3;
    }
    
    & > input[type=checkbox]:disabled ~ .caption-prepend, 
    & > input[type=checkbox]:disabled ~ .caption-append {
        color: var(--switch-toggle-disabled);
    }
    
    & > input[type=checkbox]:focus {
        box-shadow: 0 0 0 3px var(--switch-focus-color);
    }
}

.switch {
    &.material {
        & > input {
            height: 17px;
            
            &::before {
                top: -6px;
                left: -4px;
                width: 24px;
                height: 24px;
                border: 1px solid var(--switch-toggle-color);
                box-shadow: 0 2px 10px #00000029, 0 2px 5px #00000042;
            }
            
            &::after {
                top: 4px;
                transform: translateX(22px);
            }
            
            &:checked {
                &::before {
                    transform: translateX(28px);
                }
                &::after {
                    transform: translateX(4px);
                }
            }
        }
        
        .caption-prepend {
            margin-right: 8px;
        }
        .caption-append {
            margin-left: 8px;
        }
    }
}

.switch:has(input:disabled) {
    cursor: default;
}

each(@normalColors, {
    .switch-@{value} {
        --switch-background-checked: @@value!important;
    }
})